package org.cbg.panel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;

import org.cbg.bean.SearchGoodsBean;
import org.cbg.btn.TrslationBtn;
import org.cbg.frame.TrslationMainJframe;
import org.cbg.until.TraslationTableUntil;
import org.cbg.until.TreasurePavilionSearchUntil;
import org.come.Frame.ZhuFrame;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.CutButtonImage;
import org.come.until.GsonUtil;

import com.tool.tcpimg.UIUtils;

 

/**
 * 我要买装备面板
 * 
 * @author Administrator
 * 
 */

public class TraslationWantBuyZhaungbeiJpanel extends JLayeredPane {

    private static TraslationWantBuyZhaungbeiJpanel traslationWantBuyZhaungbeiJpanel;

    /**
     * 左chooseZbType 中chooseZbKind 右chooseZbAskOf 下拉框
     */
    private JLabel chooseZbType;// , chooseZbKind, chooseZbAskOf
    private JLabel yema;
    // 实例化下拉列表框
    private TraslationSelectOptionJpanel chooseZbTypeModel;// ,
    // chooseZbKindModel,chooseZbAskOfModel

    private TrslationBtn upPage, downPage, shouYe, moYe, chooseLeftArrows;
    private JLabel sortUp, sortDown;
    // 选项下拉监听标志(下拉0，没下拉1) 排序标识（0默认排序 1升序 2降序）
    private int ZbTypeFlag = 1, showOrder = 0;// , ZbKindFlag = 1, ZbAskOfFlag =
    // 1

    /**
     * 当前页码 最大页码
     *
     */
    private int dangqianyeshu = 1, zuidayema = 50;

    private JScrollPane jScrollPane;

    public TraslationWantBuyZhaungbeiJpanel() {
        // TODO Auto-generated constructor stub

        traslationWantBuyZhaungbeiJpanel = this;

        this.setPreferredSize(new Dimension(760, 460));
        this.setOpaque(false);
        this.setLayout(null);

        chooseLeftArrows = new TrslationBtn("inkImg/number/b4/xlaj.png", 1);
        chooseLeftArrows.setBounds(99, 13, 13, 13);
        chooseLeftArrows.setOpaque(false);
        this.add(chooseLeftArrows);

        chooseZbType = new JLabel("全部");
        yema = new JLabel(dangqianyeshu + "/" + zuidayema);
        yema.setHorizontalAlignment(SwingConstants.CENTER);
        chooseZbType.setForeground(Color.white);
        yema.setForeground(UIUtils.COLOR_cbg8);

        chooseZbType.setBounds(17, 8, 100, 20);
        yema.setBounds(258+91, 442, 58, 17);

        // 数据集
        String[] zbTypeData = { "全部", "常规装备", "神兵", "仙器", "配饰", "护身符", "其他" };
        // 下拉框content model (装备类型)
        chooseZbTypeModel = new TraslationSelectOptionJpanel(100, 193, "inkImg/old/1/Z1000.png", zbTypeData);
        chooseZbTypeModel.setBounds(15, 30, 100, 193);
        chooseZbTypeModel.setVisible(false);

        chooseLeftArrows.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (ZbTypeFlag == 1) {
                    chooseZbTypeModel.setVisible(true);
                    ZbTypeFlag = 0;
                } else {
                    chooseZbTypeModel.setVisible(false);
                    ZbTypeFlag = 1;
                }
            }
        });
        // 选择一个装备类型
        chooseZbTypeModel.getJlist().addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                // 设置选中值赋到jlabel上
                int count = chooseZbTypeModel.getJlist().getSelectedIndex();
                String getname = chooseZbTypeModel.getJlist().getSelectedValue();
                chooseZbType.setText(getname);

                chooseZbTypeModel.setVisible(false);
                ZbTypeFlag = 1;
                dangqianyeshu = 1;
                /**
                 * 将搜索信息传给服务器 1、初始化协议
                 * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏)
                 * 3、确认是否有二级搜索( 1 全部 2 召唤兽装备 3 地煞星符 4 宝石 5 召唤兽饰品 6 孩子装备 7 其它 8
                 * 1-14称 9 特殊召唤兽 10 高级守护 11 神兽 12 常规装备 13 神兵 14 仙器 15 配饰 16 护身符
                 * 17 灵宝 18 符石 19 道具类 20 召唤兽类 21 装备类 22 灵宝类 0 没有二级分类 ) 4、搜索条件的整合
                 * 5、转换为json字符串 6、上传给服务器
                 *
                 * start
                 */
                SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                searchGoodsBean.setSaletype(5);
                searchGoodsBean.setContiontype(TreasurePavilionSearchUntil.getEquipmentType(chooseZbType.getText()));// 根据第一个下拉框改变
                // searchGoodsBean.setSalename();
                searchGoodsBean.setPageNum(dangqianyeshu);
                searchGoodsBean.setOrder(showOrder);
                String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                        GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                SendMessageUntil.toServer(sendmes);
                TrslationMainJframe.getTrslationMainJframe().setPanelOpen(5);
                /**
                 * end
                 */
            }
        });

        jScrollPane = new JScrollPane();
        jScrollPane.setBounds(8, 63, 750, 372);
        TraslationTableUntil.TableModel(jScrollPane, 10);
        jScrollPane.getVerticalScrollBar().setUnitIncrement(50);

        // 上一页
        upPage = new TrslationBtn("inkImg/number/b4/fy2.png", 1);
        upPage.setBounds(326, 442, 19, 20);
        // 下一页
        downPage = new TrslationBtn("inkImg/number/b4/fy3.png", 1);
        downPage.setBounds(411, 442, 19, 20);
        // 首页
        shouYe = new TrslationBtn("inkImg/number/b4/fy1.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "");
        shouYe.setBounds(287, 442, 40, 20);
        // 末页
        moYe = new TrslationBtn("inkImg/number/b4/fy4.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "");
        moYe.setBounds(433, 442, 40, 20);

        upPage.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

                // 上一页
                if (dangqianyeshu > 1) {
                    dangqianyeshu--;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 将搜索信息传给服务器 1、初始化协议
                     * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏)
                     * 3、确认是否有二级搜索( 1 全部 2 召唤兽装备 3 地煞星符 4 宝石 5 召唤兽饰品 6 孩子装备 7 其它
                     * 8 1-14称 9 特殊召唤兽 10 高级守护 11 神兽 12 常规装备 13 神兵 14 仙器 15 配饰
                     * 16 护身符 17 灵宝 18 符石 19 道具类 20 召唤兽类 21 装备类 22 灵宝类 0 没有二级分类
                     * ) 4、搜索条件的整合 5、转换为json字符串 6、上传给服务器
                     *
                     * start
                     */
                    SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                    searchGoodsBean.setSaletype(5);
                    searchGoodsBean.setContiontype(TreasurePavilionSearchUntil.getEquipmentType(chooseZbType.getText()));// 根据第一个下拉框改变
                    // searchGoodsBean.setSalename();
                    searchGoodsBean.setPageNum(dangqianyeshu);
                    searchGoodsBean.setOrder(showOrder);
                    String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                    SendMessageUntil.toServer(sendmes);
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(5);
                    /**
                     * end
                     */
                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已经没有上一页了");
                }
            }
        });

        downPage.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

                // 下一页
                if (dangqianyeshu < zuidayema) {
                    dangqianyeshu++;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 将搜索信息传给服务器 1、初始化协议
                     * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏)
                     * 3、确认是否有二级搜索( 1 全部 2 召唤兽装备 3 地煞星符 4 宝石 5 召唤兽饰品 6 孩子装备 7 其它
                     * 8 1-14称 9 特殊召唤兽 10 高级守护 11 神兽 12 常规装备 13 神兵 14 仙器 15 配饰
                     * 16 护身符 17 灵宝 18 符石 19 道具类 20 召唤兽类 21 装备类 22 灵宝类 0 没有二级分类
                     * ) 4、搜索条件的整合 5、转换为json字符串 6、上传给服务器
                     *
                     * start
                     */
                    SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                    searchGoodsBean.setSaletype(5);
                    searchGoodsBean.setContiontype(TreasurePavilionSearchUntil.getEquipmentType(chooseZbType.getText()));// 根据第一个下拉框改变
                    // searchGoodsBean.setSalename();
                    searchGoodsBean.setPageNum(dangqianyeshu);
                    searchGoodsBean.setOrder(showOrder);
                    String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                    SendMessageUntil.toServer(sendmes);
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(5);
                    /**
                     * end
                     */
                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已经没有下一页了");
                }
            }
        });

        shouYe.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

                // 首页
                if (dangqianyeshu != 1) {
                    dangqianyeshu = 1;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 将搜索信息传给服务器 1、初始化协议
                     * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏)
                     * 3、确认是否有二级搜索( 1 全部 2 召唤兽装备 3 地煞星符 4 宝石 5 召唤兽饰品 6 孩子装备 7 其它
                     * 8 1-14称 9 特殊召唤兽 10 高级守护 11 神兽 12 常规装备 13 神兵 14 仙器 15 配饰
                     * 16 护身符 17 灵宝 18 符石 19 道具类 20 召唤兽类 21 装备类 22 灵宝类 0 没有二级分类
                     * ) 4、搜索条件的整合 5、转换为json字符串 6、上传给服务器
                     *
                     * start
                     */
                    SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                    searchGoodsBean.setSaletype(5);
                    searchGoodsBean.setContiontype(TreasurePavilionSearchUntil.getEquipmentType(chooseZbType.getText()));// 根据第一个下拉框改变
                    // searchGoodsBean.setSalename();
                    searchGoodsBean.setPageNum(dangqianyeshu);
                    searchGoodsBean.setOrder(showOrder);
                    String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                    SendMessageUntil.toServer(sendmes);
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(5);
                    /**
                     * end
                     */

                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已在首页");
                }
            }
        });

        moYe.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

                // 末页
                if (dangqianyeshu != zuidayema) {
                    dangqianyeshu = zuidayema;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 将搜索信息传给服务器 1、初始化协议
                     * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏)
                     * 3、确认是否有二级搜索( 1 全部 2 召唤兽装备 3 地煞星符 4 宝石 5 召唤兽饰品 6 孩子装备 7 其它
                     * 8 1-14称 9 特殊召唤兽 10 高级守护 11 神兽 12 常规装备 13 神兵 14 仙器 15 配饰
                     * 16 护身符 17 灵宝 18 符石 19 道具类 20 召唤兽类 21 装备类 22 灵宝类 0 没有二级分类
                     * ) 4、搜索条件的整合 5、转换为json字符串 6、上传给服务器
                     *
                     * start
                     */
                    SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                    searchGoodsBean.setSaletype(5);
                    searchGoodsBean.setContiontype(TreasurePavilionSearchUntil.getEquipmentType(chooseZbType.getText()));// 根据第一个下拉框改变
                    // searchGoodsBean.setSalename();
                    searchGoodsBean.setPageNum(dangqianyeshu);
                    searchGoodsBean.setOrder(showOrder);
                    String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                    SendMessageUntil.toServer(sendmes);
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(5);
                    /**
                     * end
                     */

                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已在末页");
                }
            }
        });

        sortUp = new JLabel();
        sortUp.setBounds(280, 38, 10, 18);
        sortUp.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1002.png", 10, 18));
        sortUp.setBorder(null);
        sortUp.setOpaque(false);

        sortDown = new JLabel();
        sortDown.setBounds(296, 39, 10, 18);
        sortDown.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1005.png", 10, 18));
        sortDown.setBorder(null);
        sortDown.setOpaque(false);

        // 倒序监听
        sortUp.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                sortUp.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1003.png", 10, 18));
                sortDown.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1004.png", 10, 18));
                dangqianyeshu = 1;
                showOrder = 1;

                /**
                 * 将搜索信息传给服务器 1、初始化协议
                 * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏)
                 * 3、确认是否有二级搜索( 1 全部 2 召唤兽装备 3 地煞星符 4 宝石 5 召唤兽饰品 6 孩子装备 7 其它 8
                 * 1-14称 9 特殊召唤兽 10 高级守护 11 神兽 12 常规装备 13 神兵 14 仙器 15 配饰 16 护身符
                 * 17 灵宝 18 符石 19 道具类 20 召唤兽类 21 装备类 22 灵宝类 0 没有二级分类 ) 4、搜索条件的整合
                 * 5、转换为json字符串 6、上传给服务器
                 *
                 * start
                 */
                SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                searchGoodsBean.setSaletype(5);
                searchGoodsBean.setContiontype(TreasurePavilionSearchUntil.getEquipmentType(chooseZbType.getText()));// 根据第一个下拉框改变
                // searchGoodsBean.setSalename();
                searchGoodsBean.setPageNum(dangqianyeshu);
                searchGoodsBean.setOrder(showOrder);
                String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                        GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                SendMessageUntil.toServer(sendmes);
                TrslationMainJframe.getTrslationMainJframe().setPanelOpen(5);
                /**
                 * end
                 */
            }
        });
        // 正序监听
        sortDown.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                sortUp.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1002.png", 10, 18));
                sortDown.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1005.png", 10, 18));
                dangqianyeshu = 1;
                showOrder = 2;

                /**
                 * 将搜索信息传给服务器 1、初始化协议
                 * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏)
                 * 3、确认是否有二级搜索( 1 全部 2 召唤兽装备 3 地煞星符 4 宝石 5 召唤兽饰品 6 孩子装备 7 其它 8
                 * 1-14称 9 特殊召唤兽 10 高级守护 11 神兽 12 常规装备 13 神兵 14 仙器 15 配饰 16 护身符
                 * 17 灵宝 18 符石 19 道具类 20 召唤兽类 21 装备类 22 灵宝类 0 没有二级分类 ) 4、搜索条件的整合
                 * 5、转换为json字符串 6、上传给服务器
                 *
                 * start
                 */
                SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                searchGoodsBean.setSaletype(5);
                searchGoodsBean.setContiontype(TreasurePavilionSearchUntil.getEquipmentType(chooseZbType.getText()));// 根据第一个下拉框改变
                // searchGoodsBean.setSalename();
                searchGoodsBean.setPageNum(dangqianyeshu);
                searchGoodsBean.setOrder(showOrder);
                String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                        GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                SendMessageUntil.toServer(sendmes);
                TrslationMainJframe.getTrslationMainJframe().setPanelOpen(5);
                /**
                 * end
                 */
            }
        });

        this.add(chooseZbType);
        this.add(yema);

        this.add(chooseZbTypeModel, 10, 1);
        this.add(jScrollPane, 10, -1);

        this.add(upPage);
        this.add(downPage);
        this.add(shouYe);
        this.add(moYe);
        this.add(sortUp);
        this.add(sortDown);

    }

    private ImageIcon icon1;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon1 == null) {
            icon1 = new ImageIcon("inkImg/number/b4/wpxq.png");

        }
        g.drawImage(icon1.getImage(), 0, 5, 760, 55, this);


    }

    /**
     * 刷新页面的页码
     *
     * @param dangqianyema
     * @param zuidayema
     *
     */
    public void setPage(int zuidayema) {
        this.zuidayema = zuidayema;
        yema.setText(this.dangqianyeshu + "/" + this.zuidayema);
    }

    public static TraslationWantBuyZhaungbeiJpanel getTraslationWantBuyZhaungbeiJpanel() {
        return traslationWantBuyZhaungbeiJpanel;
    }

    public static void setTraslationWantBuyZhaungbeiJpanel(
            TraslationWantBuyZhaungbeiJpanel traslationWantBuyZhaungbeiJpanel) {
        TraslationWantBuyZhaungbeiJpanel.traslationWantBuyZhaungbeiJpanel = traslationWantBuyZhaungbeiJpanel;
    }

    public JLabel getChooseZbType() {
        return chooseZbType;
    }

    public void setChooseZbType(JLabel chooseZbType) {
        this.chooseZbType = chooseZbType;
    }

    public JLabel getPage() {
        return yema;
    }

    public void setPage(JLabel page) {
        this.yema = page;
    }

    public TraslationSelectOptionJpanel getChooseZbTypeModel() {
        return chooseZbTypeModel;
    }

    public void setChooseZbTypeModel(TraslationSelectOptionJpanel chooseZbTypeModel) {
        this.chooseZbTypeModel = chooseZbTypeModel;
    }

    public TrslationBtn getUpPage() {
        return upPage;
    }

    public void setUpPage(TrslationBtn upPage) {
        this.upPage = upPage;
    }

    public TrslationBtn getDownPage() {
        return downPage;
    }

    public void setDownPage(TrslationBtn downPage) {
        this.downPage = downPage;
    }

    public TrslationBtn getShouYe() {
        return shouYe;
    }

    public void setShouYe(TrslationBtn shouYe) {
        this.shouYe = shouYe;
    }

    public TrslationBtn getMoYe() {
        return moYe;
    }

    public void setMoYe(TrslationBtn moYe) {
        this.moYe = moYe;
    }

    public TrslationBtn getChooseLeftArrows() {
        return chooseLeftArrows;
    }

    public void setChooseLeftArrows(TrslationBtn chooseLeftArrows) {
        this.chooseLeftArrows = chooseLeftArrows;
    }

    public ImageIcon getIcon1() {
        return icon1;
    }

    public void setIcon1(ImageIcon icon1) {
        this.icon1 = icon1;
    }

    public JLabel getSortUp() {
        return sortUp;
    }

    public void setSortUp(JLabel sortUp) {
        this.sortUp = sortUp;
    }

    public JLabel getSortDown() {
        return sortDown;
    }

    public void setSortDown(JLabel sortDown) {
        this.sortDown = sortDown;
    }

    public int getZbTypeFlag() {
        return ZbTypeFlag;
    }

    public void setZbTypeFlag(int zbTypeFlag) {
        ZbTypeFlag = zbTypeFlag;
    }

    public int getDangqianyeshu() {
        return dangqianyeshu;
    }

    public void setDangqianyeshu(int dangqianyeshu) {
        this.dangqianyeshu = dangqianyeshu;
    }

    public int getZuidayema() {
        return zuidayema;
    }

    public void setZuidayema(int zuidayema) {
        this.zuidayema = zuidayema;
    }

    public JScrollPane getjScrollPane() {
        return jScrollPane;
    }

    public void setjScrollPane(JScrollPane jScrollPane) {
        this.jScrollPane = jScrollPane;
    }

    public JLabel getYema() {
        return yema;
    }

    public void setYema(JLabel yema) {
        this.yema = yema;
    }

    public int getShowOrder() {
        return showOrder;
    }

    public void setShowOrder(int showOrder) {
        this.showOrder = showOrder;
    }

}
